package org.smart4j.chapter5;

import org.smart4j.framework.helper.DatabaseHelper;
import org.smart4j.plugin.security.SmartSecurity;

import java.util.Set;

/**
 * @author djw E-mail:***@***.com
 * @version 创建时间：2017/10/29 19:36
 */
public class AppSecurity implements SmartSecurity{
    @Override
    public String getPassword(String username) {
        String sql="select password from user where username=?";
        return DatabaseHelper.query(sql,username);
    }

    @Override
    public Set<String> getRoleNameSet(String username) {
        String sql="select r.role_name form user u,user_role ur,role r where u.id=ur.user_id and r.id=ur.role_id and u.username=?";
        return DatabaseHelper.querySet(sql,username);
    }

    @Override
    public Set<String> getPermissionNameSet(String roleName) {
        String sql="select p.permission_name form role r,role_permission rp,permission p " +
                "where r.id=rp.role_id and p.id=rp.permission_id and r.role_name=?";
        return DatabaseHelper.querySet(sql,roleName);
    }
}
